package com.itwlj.controller.admin;

import com.itwlj.dto.SpecDTO;
import com.itwlj.dto.SpecPageQueryDTO;
import com.itwlj.result.PageResult;
import com.itwlj.result.Result;
import com.itwlj.service.SpecService;
import com.itwlj.vo.SpecVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 规格管理
 */
@RestController
@RequestMapping("admin/spec")
@Api(tags = "规格相关接口")
@Slf4j
public class SpecController {

    @Autowired
    private SpecService specService;

    /**
     * 新增规格
     *
     * @param specDTO
     * @return
     */
    @PostMapping
    @ApiOperation("新增规格")
    public Result<String> insert(@RequestBody SpecDTO specDTO) {
        log.info("新增规格：{}", specDTO);
        specService.insert(specDTO);
        return Result.success();
    }

    /**
     * 规格分页查询
     *
     * @param specPageQueryDTO
     * @return
     */
    @GetMapping("/page")
    @ApiOperation("规格分页查询")
    public Result<PageResult> page(SpecPageQueryDTO specPageQueryDTO) {
        log.info("规格分页查询：{}", specPageQueryDTO);
        PageResult pageResult = specService.pageQuery(specPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 删除规格
     *
     * @param ids
     * @return
     */
    @DeleteMapping
    @ApiOperation("删除规格")
    public Result<String> delete(@RequestParam List<Long> ids) {
        log.info("删除规格：{}", ids);
        specService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 查询规格
     *
     * @return
     */
    @GetMapping
    @ApiOperation("查询规格")
    public Result<List<SpecVO>> list() {
        log.info("查询规格");
        List<SpecVO> specVOList = specService.list();
        return Result.success(specVOList);
    }
}
